/* 
 * Copyright (C) 2012 UTSChedule
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package utsc.apps.utschedule.ui;

import com.actionbarsherlock.app.SherlockFragment;

import utsc.apps.utschedule.R;
import utsc.apps.utschedule.ui.activities.AssignmentExamMainActivity;
import utsc.apps.utschedule.ui.activities.CalculatorMainActivity;
import utsc.apps.utschedule.ui.activities.SettingActivity;
import utsc.apps.utschedule.ui.activities.StockSettingActivity;
import utsc.apps.utschedule.ui.activities.TimetableMainActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * This is the fragment to hold the dashboard layout
 *
 */
public class DashboardFragment extends SherlockFragment implements OnClickListener{
	
	private Button _btnTimetable;
	private Button _btnAssignment;
	private Button _btnCalculator;
	private Button _btnSettings;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View dashboardHome=inflater.inflate(R.layout.fragment_dashboardlayout, container);
		_btnTimetable=(Button) dashboardHome.findViewById(R.id.btn_timetable);
		_btnTimetable.setOnClickListener(this);
		
		_btnAssignment=(Button) dashboardHome.findViewById(R.id.btn_assignment);
		_btnAssignment.setOnClickListener(this);
		
		_btnCalculator=(Button) dashboardHome.findViewById(R.id.btn_calculator);
		_btnCalculator.setOnClickListener(this);
		
		_btnSettings=(Button) dashboardHome.findViewById(R.id.btn_settings);
		_btnSettings.setOnClickListener(this);
		return dashboardHome;
	}
		
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_timetable:
			Intent timetableIntent=new Intent(getSherlockActivity(), TimetableMainActivity.class);
			startActivity(timetableIntent);
			break;
		case R.id.btn_assignment:
			Intent assignmentIntent=new Intent(getSherlockActivity().getApplicationContext(), AssignmentExamMainActivity.class);
			assignmentIntent.putExtra("fromActivity", getSherlockActivity().getClass().getName());
			startActivity(assignmentIntent);
			break;
		case R.id.btn_calculator:
			Intent calculatorIntent=new Intent(getSherlockActivity().getApplicationContext(), CalculatorMainActivity.class);
			calculatorIntent.putExtra("fromActivity", getSherlockActivity().getClass().getName());
			startActivity(calculatorIntent);
			break;
		case R.id.btn_settings:
			Intent settingIntent=null;
			if (Build.VERSION.SDK_INT<11) {
				settingIntent=new Intent(getSherlockActivity(), SettingActivity.class);
			}else {
				settingIntent=new Intent(getSherlockActivity(), StockSettingActivity.class);
				settingIntent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, StockSettingFragment.class.getName());
				settingIntent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
			}
			startActivity(settingIntent);
			break;
		default:
			break;
		}
		
	}
}
